package test.study.mybatis.client._8_binding.jdk;

import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

@Slf4j
public class MapperProxyV2<T> implements InvocationHandler {

    private Class<T> clazz;

    public MapperProxyV2(Class<T> clazz) {
        this.clazz = clazz;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //代理对象
        log.info("proxy= {}", proxy);
        //执行方法
        log.info("method= {}", method);
        //方法参数
        log.info("args= {}", args);

        if (Object.class.equals(method.getDeclaringClass())) {
            try {
                //诸如hashCode()、toString()、equals()等方法，将target指向当前对象this
                return method.invoke(this, args);
            } catch (Exception ex) {
            }
        }
        //（★）投鞭断流
        User user = new User(1L, "wangzhj", 36);
        return user;
    }
}
